[ISAPI_Rewrite]

# ============= IGNORE FRONTPAGE =============
RewriteCond User-Agent: .*MSFrontPage.*
RewriteRule (.*) $1 [L]

# ============== IGNORE FOLDERS AND FILES ==============
#
# Note that in EonicWeb, a root level page (i.e. a page under the top level page) 
#   cannot have a page name that matches these folder names.
#
# The folders that have two rules, one to pick up just the folder (e.g. the url is only "/images")
#   and one to pick the folder's subcontent (e.g. if it begins "/images/")
#   This avoids a situation where images is a substring of a longer page name 
#   (e.g. /imagesize.asp or /images of the day/)
#

RewriteHeader URL ^/googlesitemap.xml$ /ewcommon/feeds/google/sitemap.ashx [I,L,U]
RewriteHeader URL ^/googlebaseproducts.xml$ /ewcommon/feeds/google/base.ashx [I,L,U]

# IGNORE :  a URL of '/'
RewriteHeader URL ^/$ /ewcommon/default.ashx [L]

# Redirect :  /admin
RewriteHeader URL ^/admin$ /ewcommon/admin [I,L,U]

# Redirect :  /newsAdmin
RewriteHeader URL ^/newsAdmin$ /ewcommon/newsletter [I,L,U]

# Theoretically, you shouldn't need these folder ignores as Rules 2 and 3 deal with them.
# IGNORE :  /common
RewriteHeader URL ^(/common(/(.*))?)$ $1 [I,L]

# IGNORE :  /ewcommon
RewriteHeader URL ^(/ewcommon(/(.*))?)$ $1 [I,L]

# IGNORE :  /css
RewriteHeader URL ^(/css(/(.*))?)$ $1 [I,L]

# IGNORE :  /docs
RewriteHeader URL ^(/docs(/(.*))?)$ $1 [I,L]

# IGNORE :  /images
RewriteHeader URL ^(/images(/(.*))?)$ $1 [I,L]

# IGNORE :  /xsl
RewriteHeader URL ^(/xsl(/(.*))?)$ $1 [I,L]



# ============ FILES TO PROCESS ============

# Rule 1 - Redirect anything that starts with a querystring (i.e. ?)
RewriteHeader URL ^/(\?(.*))$ /ewcommon/default.ashx$1 [I,L,U]

# Rule 2 - Deal with articles (i.e. /itemNNNNN)
RewriteHeader URL ^/(.+/)*(?!.*\.\w{2,4}([\?\#]|$))(item(\d+))/?(\?(.*))?$  /ewcommon/default.ashx\?path=/$1&artid=$4?6&$6 [I,L,U]

# Rule 3 - Deal with normal path
RewriteHeader URL ^/(.+/)*(?!.*\.\w{2,4}([\?\#]|$))([^\?]+?)(\?(.*))?$ /ewcommon/default.ashx\?path=/?5$1$3&$5:$1$3 [I,L,U]


# NOTES ON PATH RULES
#   
#   A normal path match rule is can be stated as follows:
#
#		PATH = / + any subfolders + anything that is not a valid filename + querystring.
#
#		This can be broken down as follows:
#
#		1.  Begins with a /
#		2.  We may have subfolders.  A subfolder is a series of characters followed by a /.  A subfolder may occur zero or more times.
#		3.  We are now at the end of the string - let's check it's not a valid file request (e.g. default.asp)
#				- a valid file is a number of chars followed by a full stop followed by 2-4 alphanumerics followed by either a ? or # or end of string
#		4.  If it is not a valid file we expect a number of non-question marks, optionally followed by a ? and following chars.
#
#   Note this applies to Rule 3.  Rule 2 is slightly different in that it looks for an "item" - same principles apply
